$(function () {
    $('#page').load('page.html');
})

function FindAll() {
    let da={
        jurisdictionCode:$.trim($("#jurisdiction_code").val()),
        value:$.trim($("#value").val()),
        jurisdictionName:$.trim($("#jurisdiction_name").val()),
        status:$("#isStart").val(),
        pageSize:$("#pageSize").val(),
        pageNum:$("#pageNum").val(),
    };
    let data=myAjax("/jurisdiction/jurisdictionConditionFind",da,"post");
    if (data.code==403){
        alert("没有相关权限");
        window.open("index.html","_self");
    }else {
        $("#pageCount").text(data.data.total);
        data=data.data.list;
        let html='';
        let thaw;
        let method;
        let isStart;
        for (let i=0;i<data.length;i++){
            if (data[i].status==1){
                isStart='是' ;
                thaw='禁用';
                method='FrozenById';
            }else if (data[i].status==-1){
                isStart='否' ;
                thaw='启用';
                method='ThawById';
            }
            html +='        <tr>\n' +
                '            <td>'+data[i].id+'</td>\n' +
                '            <td>'+data[i].jurisdictionCode+'</td>\n' +
                '            <td>'+data[i].value+'</td>\n' +
                '            <td>'+data[i].jurisdictionName+'</td>\n' +
                '            <td>'+isStart+'<a class="isStatus" href="javascript:'+method+'('+data[i].id+')">'+thaw+'</a></td>\n' +
                '            <td><input type="button" value="删除" onclick="jurisdictionDeleteById('+data[i].id+')"></td>\n' +
                '        </tr>';
        }
        $("#jurisdictionFandAll").html(html);
    }
}
function ThawById(id) {
    let da={
        id:id,
        status:1
    }
    let data=myAjax("/jurisdiction/jurisdictionFrozenOrThawById",da,"post");
    if (data.code==403){
        alert("没有相关权限");
        window.open("index.html","_self");
    }else {
        data = data.code;
        if (data == 200) {
            alert('权限启用成功')
        } else if (data == 500) {
            alert('权限启用失败')
        }
        FindAll();
    }
}

function FrozenById(id) {
    let da={
        id:id,
        status:-1
    }
    let data=myAjax("/jurisdiction/jurisdictionFrozenOrThawById",da,"post");
    if (data.code==403){
        alert("没有相关权限");
        window.open("index.html","_self");
    }else {
        data = data.code;
        if (data == 200) {
            alert('权限禁用成功')
        } else if (data == 500) {
            alert('权限禁用失败')
        }
        FindAll();
    }
}


function jurisdictionDeleteById(id) {
    let data=myAjaxGet("/jurisdiction/jurisdictionDeleteById",{id:id},"get");
    if (data.code==403){
        alert("没有相关权限");
        window.open("index.html","_self");
    }else {
        data = data.code;
        if (data == 200) {
            alert("删除权限成功!");
            $('#middle-reght').load('jurisdiction/jurisdiction.html');
        } else if (data == 500) {
            alert("删除权限失败!");
        }
    }
}